﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using BLToolkit.Data;
using BLToolkit.Data.Linq;

namespace DAL
{
    public class KhachHangRepository : IKhachHangRepository
    {
        public DbManager db = new DbManager("QuanLyBilliards");

        public KhachHang GetById(string maKH)
        {
            return db.GetTable<KhachHang>().SingleOrDefault(x => x.MaKH == maKH);
        }

        public IQueryable<KhachHang> GetAll()
        {
            return db.GetTable<KhachHang>();
        }

        public bool AddNew(KhachHang khachHang)
        {
            return db.Insert(khachHang) > 0;

        }

        public bool Update(KhachHang khachHang)
        {
            return db.Update(khachHang) > 0;
        


        }

        public bool Delete(KhachHang khachHang)
        {
            return db.Delete(khachHang) > 0;
        }

        public IQueryable<KhachHang> FindTenKH(string ten)
        {
            return db.GetTable<KhachHang>().Where(x => x.TenKH.Contains(ten));
        }

        public IQueryable<KhachHang> FindDiaChi(string diachi)
        {
            return db.GetTable<KhachHang>().Where(x => x.DiaChi.Contains(diachi));
        }

        public IQueryable<KhachHang> FindSoDT(string SoDT)
        {
            return db.GetTable<KhachHang>().Where(x => x.SoDT.Contains(SoDT));
        }


      
    }
}
